package com.t174.car.controller;

import com.t174.car.dao.SupplierDao;
import com.t174.car.entity.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/supplier")
@Scope("prototype")
public class SupplierController {
    @Autowired
    SupplierDao supplierDao;
    @RequestMapping("/cha")
    @ResponseBody
    public List<Supplier> showcha(){
        return supplierDao.query();
    }
    @RequestMapping("/dele")
    @ResponseBody
    public int del(String ids){
        String[] ss = ids.split("-");
        Integer[] myids = new Integer[ss.length] ;
        for(int i=0;i<ss.length;i++){
            System.out.println(ss[i]);
            myids[i] = Integer.parseInt(ss[i]) ;
        }
        return supplierDao.delSupplier(myids);
    }

    @RequestMapping("/add")
    @ResponseBody
    public  int addSupplier(Supplier supplier){
        return supplierDao.addSupplier(supplier);
    }
    @RequestMapping("/getsupplier")
    @ResponseBody
    public Supplier getSupplier(int id){

        return supplierDao.getSupplier(id);
    }

    @RequestMapping("/upsupplier")
    @ResponseBody
    public int updateGuests(Supplier supplier){

        return supplierDao.updateSupplier(supplier);
    }

}
